// 输入框限制为字母，数字或中文
export const verificTextInput = (e,n) => {
  var s = n ? n : 20
  var v = e ? e.replace(/[^\a-\z\A-\Z0-9\u4e00-\u9fe5_]/g,'').slice(0, s) : ''
  return v
}

// 输入框限制为字母，数字或中文
export const customTextInput = (e,n) => {
  var s = n ? n : 20
  var v = e ? e.replace(/[^\a-\z\A-\Z0-9!@#$%^&*()\s\[\]\{\}\-\_.,?/'";:><\u4e00-\u9fe5]/g,'').slice(0, s) : ''
  return v
}

// 输入框限制字符
export const notLimitTextInput = (e,n) => {
  var s = n ? n : 20
  var v = e ? e.slice(0, s) : ''
  return v
}

// 输入框限制为字母，数字或英文符号
export const customTextInput1 = (e,n) => {
  var s = n ? n : 20
  var v = e ? e.replace(/[^a-zA-Z0-9!@#$%^&*()\s\[\]\{\}\-\_.,?/'";:><]/g,'').slice(0, s) : ''
  return v
}

// 输入框限制为字母，数字，不能以0开头
export const loginAccount = (e,n) => {
  var s = n ? n : 20
  e = e && e[0]=='0'? e.substring(1) : e
  var v = e ? e.replace(/[^a-zA-Z0-9]/g,'').slice(0, s) : ''
  return v
}

// 输入框限制为字母，数字
export const verificAlphanumeric = (e,n) => {
  var s = n ? n : 20
  var v = e ? e.replace(/[^\a-\z\A-\Z0-9]/g,'').slice(0, s) : ''
  return v
}

// 输入框限制为字母，数字
export const verificUpperAlphanumeric = (e,n) => {
  var s = n ? n : 32
  var v = e ? e.replace(/[^\a-\z\A-\Z0-9]/g,'').slice(0, s).toUpperCase() : ''
  return v
}

// 输入框限制为数字
export const verificNumeric = (e,n) => {
  var s = n ? n : 20
  var v = e ? e.replace(/[^0-9]/g,'').slice(0, s) : ''
  return v
}

// 输入框限制为字母，数字
export const verificLowerAlphanumeric = (e,n) => {
  var s = n ? n : 32
  var v = e ? e.replace(/[^\a-\z\A-\Z0-9]/g,'').slice(0, s).toLowerCase() : ''
  return v
}

// 输入框限制为纯数字
export const verificNumberInput = (e,n) => {
  console.log(e,"verificNumberInput")
  if(e==undefined) return 0
  var v = e.toString().replace(/[^0-9]/g,'')
  return n ? + v < n ? n : + v : + v
}

//输入框限制整数范围
// n:原输入，minV,maxV为数值范围，defV：默认值
export const verficNumber = (n,minV,maxV,defV) => {
  var v = n.toString().replace(/[^\d]/g, "");
  if (v < minV || v > maxV || isNaN(v)) {
    v = defV || minV;
  }
  return Number(v);
}

// 校验手机号是否正确
export const verificPhone = (e) => {
  const reg = /^[1][3,4,5,6,7,8,9][0-9]{9}$/;
  var test = ""
  if (e.length >= 11) {
    if (!reg.test(e)) {
      test = "输入的手机号码不正确";
    }
  } else {
    test = "";
  }
  return test
}

// 校验身份证是否正确
export const verificIdCard = (e) => {
  const reg = /(^\d{8}(0\d|10|11|12)([0-2]\d|30|31)\d{3}$)|(^\d{6}(18|19|20)\d{2}(0\d|10|11|12)([0-2]\d|30|31)\d{3}(\d|X|x)$)/;
  var test = ""
  if (e.length >= 18) {
    if (!reg.test(e)) {
      test = "输入的身份证号码不正确";
    }
  } else {
    test = "";
  }
  return test
}

// 身份证输入限制
export const verificIdCardNumber =(e, n) => {
  var v = e.toString().substring(0,17).replace(/[^\d]/g, "") + e.toString().substring(17).replace(/[^\dXx]/g, "")
  var v = v.slice(0, 18);
  return v
}
